package com.example.springbootws.config;

import com.example.springbootws.service.UserService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @program: springboot-ws
 * @description:
 * @author: ruge.wu
 * @create: 2021-09-17 08:59
 **/
@Configuration
public class JaxWsConfig {
    @Autowired
    private Bus bus;
    @Autowired
    private UserService userService;

    /**
     * 此方法作用是改变项目中服务名的前缀名，此处127.0.0.1或者localhost不能访问时，请使用ipconfig查看本机ip来访问
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/sapStock?wsdl
     * 去掉注释后：wsdl访问地址为：http://127.0.0.1:8080/soap/sapStock?wsdl
     *
     */
    @SuppressWarnings("all")
//    @Bean
//    public ServletRegistrationBean dispatcherServlet() {
//        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
//    }

    @Bean
    public Endpoint createEndpoint() {
        Endpoint endpoint = new EndpointImpl(bus, userService);
        endpoint.publish("/sapStock");
        return endpoint;
    }
}
